﻿using System;
using System.Windows.Input;
using MVVM.Northwind.Employee.Commands;

namespace MVVM.Northwind.Employee.ViewModel
{
    public abstract class WorkspaceViewModel:ViewModelBase
    {
        MVVMRoutedCommand _closeCommad;
        public event EventHandler RequestClose;

        public static string str = string.Empty;

        protected WorkspaceViewModel() { }
        
        /// <summary>
        /// 
        /// </summary>
        public ICommand CloseCommand
        {
            get
            {
                if (_closeCommad==null)
                {
                    _closeCommad = new MVVMRoutedCommand
                        ((param) => this.OnRequestClose(), (param)=>this.OnRequestCanClose());
                    
                }
                return _closeCommad;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private void OnRequestClose()
        {
            EventHandler handler = this.RequestClose;
            if (handler!=null)
            {
                handler(this, EventArgs.Empty);
            }
        }
        private bool OnRequestCanClose()
        {
            return true;
        }
    }
}
